#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct student
{
    string name, gender, id;
    int grade;
};
bool cmp1(student s1, student s2)
{
    return s1.grade < s2.grade;
}
bool cmp2(student s1, student s2)
{
    return s1.grade > s2.grade;
}
int main()
{
    int n, flag = 0;
    cin >> n;
    student stu;
    vector<student> boys, girls;
    for (int i = 0; i < n; i++)
    {
        cin >> stu.name >> stu.gender >> stu.id >> stu.grade;
        if (stu.gender == "M")
            boys.push_back(stu);
        else
            girls.push_back(stu);
    }
    sort(boys.begin(), boys.end(), cmp1);
    sort(girls.begin(), girls.end(), cmp2);
    if (girls.empty())
    {
        cout << "Absent" << endl;
        flag = 1;
    }
    else
    {
        cout << girls[0].name << " " << girls[0].id << endl;
    }
    if (boys.empty())
    {
        cout << "Absent" << endl;
        flag = 1;
    }
    else
    {
        cout << boys[0].name << " " << boys[0].id << endl;
    }
    if(flag)
        cout << "NA";
    else
        cout << girls[0].grade - boys[0].grade;
    return 0;
}